<?php
/**************************************************************************************************
 *  File Definition 
 *  - Manage Database
 -------------------------------------------------------------------  
 *  Apprain : Content Management Framework <http://www.apprain.com/>
 *  Download link: http://www.apprain.com/download
 *  Docs link: http://www.apprain.com/docs
 -------------------------------------------------------------------
 *  License text http://www.opensource.org/licenses/mit-license.php 
 *  About MIT license <http://en.wikipedia.org/wiki/MIT_License/>
*************************************************************************************************/

echo $this->get_tag('div',array('class'=>'app_form'));
    // Export Database
    echo $this->callElement("default/tools/tool_bar",array("buttons"=>array(array("type"=>"back")) ,"title" => "Export Databse")); 
    echo $this->get_tag("p","Download Database in a XML formate with SCHEMA and DATA");
    
    echo $this->get_tag("form",array("method"=>"POST","action"=>$this->baseurl("/developer/imexport")));
        echo App::load("Helper/Html")->submitTag("data[ImExport][export]","Export",array("class"=>"app_button"));
    echo $this->get_tag("/form");

    echo "<br /><br />";
    echo $this->callElement("default/tools/tool_bar",array("buttons"=>array(array("type"=>"back")) ,"title" => "Import Databse")); 
    echo $this->get_tag("p","For security reason we don't Drop/Create database table. But we truncate all previous data during restore. 
                            <br /> <strong>Important</strong>
                            <br /> 1. Save a copy of your previous database before import
                            <br /> 2. Database schema must be same with the imported one ");
    echo $this->get_tag("form",array("method"=>"POST","action"=>$this->baseurl("/developer/imexport"),"enctype"=>"multipart/form-data"));
    echo $this->get_tag("p",array("class"=>"message"),$import_err);
    echo App::load("Helper/Html")->fileTag("data[ImExport][filename]");
    echo " ";
    echo App::load("Helper/Html")->submitTag("data[ImExport][import]","Import",array("class"=>"app_button"));
    echo $this->get_tag("/form");

    echo "<br /><br />";
    echo $this->callElement("default/tools/tool_bar",array("buttons"=>array(array("type"=>"back")) ,"title" => "Backup Databse")); 
    echo $this->get_tag("p",array("class"=>"message"),$backup_err);
    if( isset($database_files['file']))
    {
        foreach ( $database_files['file'] as $val )
        {
            echo App::load("Helper/Html")->linkTag($this->baseurl("/common/download/" . base64_encode(DATA . DS . "database/{$val['name']}")),"<em>Download</em>");
            echo " - ";
            echo App::load("Helper/Html")->linkTag($this->baseurl("/developer/imexport/delete/" .base64_encode($val['name'])),"<em>Delete</em>");
            echo " - ";
            echo $this->get_tag("span",$val['name']);
            echo "<br />";
        }
        echo "<br />";
    }
    echo $this->get_tag("form",array("method"=>"POST","action"=>$this->baseurl("/developer/imexport"),"enctype"=>"multipart/form-data"));
    echo App::load("Helper/Html")->inputTag("data[ImExport][filename]",date("Y-m-d_H-i-s"),array("size"=>"30"));
    echo " ";
    echo App::load("Helper/Html")->submitTag("data[ImExport][backup]","Backup",array("class"=>"app_button"));
    echo $this->get_tag("/form");

    echo "<br /><br />";
    echo $this->callElement("default/tools/tool_bar",array("buttons"=>array(array("type"=>"back")) ,"title" => "Restore Databse")); 
    echo $this->get_tag("p",array("class"=>"message"),$restore_err);
    echo $this->get_tag("form",array("method"=>"POST","action"=>$this->baseurl("/developer/imexport"),"enctype"=>"multipart/form-data"));

    if( isset($database_files['file']))
    {
        echo "<select name=\"data[ImExport][file_name]\"><option value=\"\">Select a version to rollback</option>";
        foreach ( $database_files['file'] as $key => $val )
        {
            echo "<option  value=\"{$val['name']}\">{$val['name']}</option>" ;
        }
        echo "</select>";
        echo "<br /><br />";
    }
    echo App::load("Helper/Html")->submitTag("data[ImExport][restore]","Restore",array("class"=>"app_button"));
    echo "<br /><br />";
    echo $this->get_tag("/form");

    echo $this->callElement("default/tools/tool_bar",array("buttons"=>array(array("type"=>"back")) ,"title" => NULL)); 
echo $this->get_tag('/div');
